        var cmcStore = new Ext.data.JsonStore({
    		url: '/weihe/getItems_contractList',
			root: 'datas',
			fields : [{
			        	   name:'cmcId',mapping:'id'
			          },{
			        	   name:'cmcName',mapping:'name'
			          },{
			        	   name:'cmcQuantity',mapping:'quantity' 
			          },{
        				   name:'cmcPrice',mapping:'price'
        			  },{
        				   name:'cmcUnit',mapping:'unit'
        			  },{
        				   name:'cmcAmount',mapping:'amount'
        			  }],
					listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_contractList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});
        
        var cmcListStore = new Ext.data.JsonStore({
			url: '/weihe/getList_cmcList',
			root: 'datas',
			fields : [{
			        	   name:'cmcListId',mapping:'id'
			          },{
			        	   name:'cmcListNum',mapping:'listNum' 
			          },{
			        	   name:'cmcMes',mapping:'mes' 
			          },{
			        	   name:'cmcTel',mapping:'tel' 
			          },{
			        	   name:'cmcTotal',mapping:'total' 
			          },{
        				   name:'cmcDate', mapping:'date',type : 'date', dateFormat:"Y-m-d"
        			  },{
			        	   name:'cmcAddr',mapping:'addr' 
			          },{
			        	   name:'cmcSud',mapping:'sud' 
			          },{
			        	   name:'cmcPayment',mapping:'payment' 
			          }],
					listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_cmcList',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});
        
       
        
cmcs = function(){
	
	var tmp='';

	
  return{
	  
	  
		listPanel : function(){
	  
		var listPanel = new Ext.Panel( {
			                    region : 'north',
			                    layout : 'border',
			                    frame  : true,
			                    height :250,
			                    items  : [cmcs.listGrid(),cmcs.listForm()] 
		                      });
	  
	  return listPanel;
},

listForm : function(){
	  	var codestore = new Ext.data.JsonStore({
			url: '/weihe/getCmcByListNum_cmcList',
			root: 'nums',
			fields: ['num']
		
		});
		
		var codeCombo = {
				id : 'cmcListNum',
				xtype: 'combo',
				fieldLabel: 'INVOICE N0.',
				store: codestore,
				typeAhead: false,
				name: 'commercialList.listNum',
				loadingText: '查找中...',
				emptyText: '请输入3位以上单号', 
				minChars: 3,
				pageSize: 0,
				hideTrigger: true,
				editable: true,
				triggerAction: 'all',
				displayField : 'num',
				listeners :{ 'select':function(combo, record,index){
							Ext.Ajax.request({
								url : '/weihe/getCmc_cmcList',
								success : function(response) {
									  var json = Ext.decode(response.responseText);
									  listForm.form.findField('cmcMes').setValue(json.mes);
									  listForm.form.findField('cmcAddr').setValue(json.addr);
									  listForm.form.findField('cmcTel').setValue(json.tel);
									  listForm.form.findField('cmcTotal').setValue(json.total);
									  listForm.form.findField('cmcPayment').setValue(json.payment);
									  
									},
								params : {'query' : record.get('num')}
							});
				    }
				}
		};
    


		var button_add = new Ext.Button({
			text : '添加',
			handler : function() {
				progressConsole();
				if(listForm.form.isValid()){ 
					if (listForm.form.findField("cmcListId").getValue() == "") {
						 listForm.form.submit({
						     url : '/weihe/add_cmcList',
						     success : function(form, action) {
							      if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
								        Ext.Msg.alert('消息', action.result.msg, function() {
								        listForm.form.findField('commercialList.id').setValue(action.result.cmcList_id);
									    Ext.getCmp("cmcListGrid").getStore().load({params : {start : action.result.total-1, limit : 5}});
									    listForm.buttons[0].setText('修改');
								        })
							       }
						     }
					      })
					}else {
							listForm.form.submit({
								url : '/weihe/update_cmcList',
								success : function(form, action) {
									if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
										Ext.Msg.alert('消息', action.result.msg, function() {
											Ext.getCmp("cmcListGrid").getStore().load({params : {start : 0, limit : 5}});
										})
									}
							   }
							})
					}
				}else{
					Ext.Msg.alert('提示','请输入相关内容');
				}
			}
		});

	var button_clear = new Ext.Button({
		text : '清空',
		handler : function() {
		
			listForm.form.reset();
			listForm.buttons[0].setText('添加');
		    Ext.getCmp("cmcGrid").getStore().removeAll();
		}
	});

	var button_del = new Ext.Button({
		text : '删除',
		handler : function() {
			var id = listForm.form.findField('cmcListId').getValue();
			if (id == '') {
				Ext.Msg.alert('提示', '请选择需要删除的信息!');
			} else {
				progressConsole();
				Ext.Ajax.request({
					url : '/weihe/delete_cmcList',
					success : function(response) {
						var json = Ext.decode(response.responseText);
						if (json.success) {
							  if (json.deny) {
									Ext.Msg.alert('错误',json.msg);
									listForm.form.reset();
								    listForm.buttons[0].setText('添加');
						  }else{
							Ext.Msg.alert('消息', json.msg, function() {
								Ext.getCmp("cmcListGrid").getStore().load({params : {start : 0, limit : 5}});
								listForm.form.reset();
								listForm.buttons[0].setText('添加');
							});
						  }
						}else{
							Ext.Msg.alert('消息', json.msg);
						}
					},
					failure : function() {
						Ext.Msg.alert('错误', '删除失败!');
					},
					params: { 'commercialList.id' : listForm.form.findField('cmcListId').getValue() }
				});
			}
		}
	});
	
	  
			var listForm = new Ext.form.FormPanel({
			id : 'cmcListForm',
			region : 'east',
			title : '发票信息',
			frame : true,
			width : 330,
			autoScroll : true,
			labelAlign : 'right',
			labelWidth : 85,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{  
				id: 'cmcListId',
				xtype : 'hidden',  
				name : 'commercialList.id'
			},{  
				id: 'cmcTotal',
				xtype : 'hidden',  
				name : 'commercialList.total'
			},codeCombo,{
				id: 'cmcDate',
                xtype: 'datefield',
                fieldLabel: "日期", 
                format : 'Y-m-d',
    			allowBlank:false,
                name: "commercialList.date"
			},{
				id: 'cmcMes',
				fieldLabel: "TO MESSRS",
				name: "commercialList.mes"
			},{
				id: 'cmcTel',
				fieldLabel: "TEL",
				name: "commercialList.tel"
			},{
				id: 'cmcAddr',
				fieldLabel: "ADD",
				name: "commercialList.addr"
			},{
				id: 'cmcPayment',
				fieldLabel: "PAYMENT",
				name: "commercialList.payment"
			},{
				id: 'cmcSud',
				fieldLabel: "SUD",
				name: "commercialList.sud"
			}],
			buttons : [button_add,button_clear,button_del]
	});
	  
	  return listForm;
},  
	  
	  
  listGrid : function(){
	  
		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 5,
			store : cmcListStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		   
	   var listGrid = new Ext.grid.GridPanel({
		   id:'cmcListGrid',
		   region : 'center',
		   minColumnWidth : 35,
		   loadMask : {msg:'正在加载数据，请稍侯...'},
		   tbar:[{
			  	text:"打印发票",
				handler:function(){
							if(tmp!=''){
			   				window.open('/weihe/printCmc?commercialList.id='+ tmp, '_blank');
			   				tmp = '';
							}else{
								Ext.Msg.alert('提示','请选择要打印的数据!');
							}
				}
						
		   		},"-"],
		   store : cmcListStore,
		   columns: [
		             {header : 'INVOICE_NO.', dataIndex : 'cmcListNum',sortable : true},
		             {header : 'DATE', dataIndex : 'cmcDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y年m月d日')},
		             {header : 'TO_MESSRS', dataIndex : 'cmcMes'},
		             {header : 'TEL', dataIndex : 'cmcTel'},
		             {header : 'ADD', dataIndex : 'cmcAddr'},
		             {header : 'PAYMENT', dataIndex : 'cmcPayment'},
		             {header : 'TOTAL', dataIndex : 'cmcTotal'},
		             {header : 'SUD', dataIndex : 'cmcSud'}
		             ],
         sm : rowSelectionModel,
         listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   		var record = grid.getStore().getAt(rowIndex);
			   		tmp = record.id;
			   		Ext.getCmp("cmcListForm").form.loadRecord(record);
					Ext.getCmp("cmcListForm").buttons[0].setText('修改');
					Ext.getCmp("cmcGrid").getStore().baseParams = {'contractList.listNum': record.get('cmcListNum')};
					Ext.getCmp("cmcGrid").getStore().load({params : {start : 0, limit : 5}});
		   		}
		   },
		  bbar : pageToolBar
});
		return listGrid;
	},
  
    grid : function(){
	 


		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 5,
			store : cmcStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		   


		});


		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		   
	   var grid = new Ext.grid.GridPanel({
		   id:'cmcGrid',
		   title : '货物信息表',
		   region : 'center',
		   minColumnWidth : 50,
		   loadMask : {msg:'正在加载数据，请稍侯...'}, // 单击分页时显示,为true显示'Loading...'
		   store : cmcStore,
		   columns: [
		             {header : '商品名称', dataIndex : 'cmcName', menuDisabled : true},
		             {header : '商品单位', dataIndex : 'cmcUnit', menuDisabled : true},
		             {header : '商品数量', dataIndex : 'cmcQuantity', menuDisabled : true},
		             {header : '价格', dataIndex : 'cmcPrice', menuDisabled : true},
		             {header : '金额', dataIndex : 'cmcAmount', menuDisabled : true}
        ],
           sm : rowSelectionModel,
		   viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return grid;
	}
  }
}();








